home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 60 / 60.xpi / chrome / webdeveloper.jar / content / webdeveloper / common / preferences.js < prev    next >
Encoding:
Text File  |  2009-06-30  |  5.0 KB  |  183 lines

  1. var webdeveloper_preferencesService = null;
  2.  
  3. // Deletes a preference
  4. function webdeveloper_deletePreference(preference)
  5. {
  6.     // If the preference is set
  7.     if(preference)
  8.     {
  9.         // If a user preference is set
  10.         if(webdeveloper_isPreferenceSet(preference))
  11.         {
  12.             webdeveloper_getPreferencesService().clearUserPref(preference);
  13.         }
  14.     }
  15. }
  16.  
  17. // Deletes a preference branch
  18. function webdeveloper_deletePreferenceBranch(branch)
  19. {
  20.     // If the branch is set
  21.     if(branch)
  22.     {
  23.         webdeveloper_getPreferencesService().deleteBranch(branch);
  24.     }
  25. }
  26.  
  27. // Gets a boolean preference, returning false if the preference is not set
  28. function webdeveloper_getBooleanPreference(preference, userPreference)
  29. {
  30.     // If the preference is set
  31.     if(preference)
  32.     {
  33.         // If not a user preference or a user preference is set
  34.         if(!userPreference || webdeveloper_isPreferenceSet(preference))
  35.         {
  36.             try
  37.             {
  38.                 return webdeveloper_getPreferencesService().getBoolPref(preference);
  39.             }
  40.             catch(exception)
  41.             {
  42.                 // Do nothing
  43.             }
  44.         }
  45.     }
  46.  
  47.     return false;
  48. }
  49.  
  50. // Gets an integer preference, returning 0 if the preference is not set
  51. function webdeveloper_getIntegerPreference(preference, userPreference)
  52. {
  53.     // If the preference is set
  54.     if(preference)
  55.     {
  56.         // If not a user preference or a user preference is set
  57.         if(!userPreference || webdeveloper_isPreferenceSet(preference))
  58.         {
  59.             try
  60.             {
  61.                 return webdeveloper_getPreferencesService().getIntPref(preference);
  62.             }
  63.             catch(exception)
  64.             {
  65.                 // Do nothing
  66.             }
  67.         }
  68.     }
  69.  
  70.     return 0;
  71. }
  72.  
  73. // Gets the preferences service
  74. function webdeveloper_getPreferencesService()
  75. {
  76.     // If the preferences service is not set
  77.     if(!webdeveloper_preferencesService)
  78.     {
  79.         webdeveloper_preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  80.     }
  81.  
  82.     return webdeveloper_preferencesService;
  83. }
  84.  
  85. // Gets a string preference, returning null if the preference is not set
  86. function webdeveloper_getStringPreference(preference, userPreference)
  87. {
  88.     // If the preference is set
  89.     if(preference)
  90.     {
  91.         // If not a user preference or a user preference is set
  92.         if(!userPreference || webdeveloper_isPreferenceSet(preference))
  93.         {
  94.             try
  95.             {
  96.                 return webdeveloper_getPreferencesService().getComplexValue(preference, Components.interfaces.nsISupportsString).data.trim();
  97.             }
  98.             catch(exception)
  99.             {
  100.                 // Do nothing
  101.             }
  102.         }
  103.     }
  104.  
  105.     return null;
  106. }
  107.  
  108. // Is a preference set
  109. function webdeveloper_isPreferenceSet(preference)
  110. {
  111.     // If the preference is set
  112.     if(preference)
  113.     {
  114.         return webdeveloper_getPreferencesService().prefHasUserValue(preference);
  115.     }
  116.  
  117.     return false;
  118. }
  119.  
  120. // Sets a boolean preference
  121. function webdeveloper_setBooleanPreference(preference, value)
  122. {
  123.     // If the preference is set
  124.     if(preference)
  125.     {
  126.         webdeveloper_getPreferencesService().setBoolPref(preference, value);
  127.     }
  128. }
  129.  
  130. // Sets a boolean preference if it is not already set
  131. function webdeveloper_setBooleanPreferenceIfNotSet(preference, value)
  132. {
  133.     // If the preference is not set
  134.     if(!webdeveloper_isPreferenceSet(preference))
  135.     {
  136.         webdeveloper_getPreferencesService().setBoolPref(preference, value);
  137.     }
  138. }
  139.  
  140. // Sets an integer preference
  141. function webdeveloper_setIntegerPreference(preference, value)
  142. {
  143.     // If the preference is set
  144.     if(preference)
  145.     {
  146.         webdeveloper_getPreferencesService().setIntPref(preference, value);
  147.     }
  148. }
  149.  
  150. // Sets an integer preference if it is not already set
  151. function webdeveloper_setIntegerPreferenceIfNotSet(preference, value)
  152. {
  153.     // If the preference is not set
  154.     if(!webdeveloper_isPreferenceSet(preference))
  155.     {
  156.         webdeveloper_setIntegerPreference(preference, value);
  157.     }
  158. }
  159.  
  160. // Sets a string preference
  161. function webdeveloper_setStringPreference(preference, value)
  162. {
  163.     // If the preference is set
  164.     if(preference)
  165.     {
  166.         var supportsStringInterface = Components.interfaces.nsISupportsString;
  167.         var string                  = Components.classes["@mozilla.org/supports-string;1"].createInstance(supportsStringInterface);
  168.  
  169.         string.data = value;
  170.  
  171.         webdeveloper_getPreferencesService().setComplexValue(preference, supportsStringInterface, string);
  172.     }
  173. }
  174.  
  175. // Sets a string preference if it is not already set
  176. function webdeveloper_setStringPreferenceIfNotSet(preference, value)
  177. {
  178.     // If the preference is not set
  179.     if(!webdeveloper_isPreferenceSet(preference))
  180.     {
  181.         webdeveloper_setStringPreference(preference, value);
  182.     }
  183. }